package com.yisu.expressway.ui.loading;

import java.util.Timer;
import java.util.TimerTask;

import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LinearInterpolator;
import android.widget.ImageView;
import android.widget.TextView;

import com.yisu.expressway.R;


/**
 * @Description:自定义对话框
 * @author http://blog.csdn.net/finddreams
 */
public class CustomProgressDialog extends ProgressDialog {

	private AnimationDrawable mAnimation;
	private Context mContext;
	private ImageView mImageView;
	private String mLoadingTip;
	private TextView mLoadingTv;
	private int count = 0;
	private String oldLoadingTip;
	private int mResid;
	Animation operatingAnim;

	public CustomProgressDialog(Context context) {
		super(context);
		this.mContext = context;
		setCanceledOnTouchOutside(true);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initView();
	}

	private void initData() {
		if (operatingAnim != null) {
			mImageView.startAnimation(operatingAnim);
		}
	}

	public void setContent(String str) {
		mLoadingTv.setText(str);
	}

	public void showLoading(){
		if (operatingAnim != null) {
			mImageView.startAnimation(operatingAnim);
		}
	}

	public void dismissLoading(){
		if (operatingAnim != null) {
			mImageView.clearAnimation();
		}
	}

	private void initView() {
		setContentView(R.layout.loading_layout);
		mImageView = (ImageView) findViewById(R.id.iv_loading);
		operatingAnim = AnimationUtils.loadAnimation(mContext, R.anim.rotate_anim);
		LinearInterpolator lin = new LinearInterpolator();
		operatingAnim.setInterpolator(lin);
	}

	/*@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		// TODO Auto-generated method stub
		mAnimation.start(); 
		super.onWindowFocusChanged(hasFocus);
	}*/
}
